//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.example.pcapnative;

import java.io.Serializable;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class LinkLayerAddress implements Serializable {
    private static final long serialVersionUID = -2832879271594305200L;
    protected static final Pattern HEX_SEPARATOR_PATTERN = Pattern.compile("([^0-9a-fA-F])");
    private final byte[] address;

    protected LinkLayerAddress(byte[] address) {
        this.address = address;
    }

    public static LinkLayerAddress getByAddress(byte[] address) {
        return new LinkLayerAddress(ByteArrays.clone(address));
    }

    public static LinkLayerAddress getByName(String name) {
        Matcher m = HEX_SEPARATOR_PATTERN.matcher(name);
        m.find();
        return getByName(name, m.group(1));
    }

    public static LinkLayerAddress getByName(String name, String separator) {
        return getByAddress(ByteArrays.parseByteArray(name, separator));
    }

    public byte[] getAddress() {
        return ByteArrays.clone(this.address);
    }

    public int length() {
        return this.address.length;
    }

    public String toString() {
        return ByteArrays.toHexString(this.address, ":");
    }

    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        } else {
            return !(obj instanceof LinkLayerAddress) ? false : Arrays.equals(((LinkLayerAddress)obj).getAddress(), this.address);
        }
    }

    public int hashCode() {
        return Arrays.hashCode(this.address);
    }
}
